Fix xm-test network tests to work with hvm support enabled.
authoradam@ipcoast.com <adam@ipcoast.com>
Fri, 10 Feb 2006 01:05:26 +0000 (02:05 +0100)
committeradam@ipcoast.com <adam@ipcoast.com>
Fri, 10 Feb 2006 01:05:26 +0000 (02:05 +0100)
tools/xm-test/lib/XmTestLib/Network.py
tools/xm-test/tests/network/02_network_local_ping_pos.py
tools/xm-test/tests/network/05_network_dom0_ping_pos.py
tools/xm-test/tests/network/11_network_domU_ping_pos.py

index 41863f3368d89f9a1ea28fd55ebb6f182b06b126..d9d12c5439f4c13fe3f1a5326e8023d19906a784 100644 (file)
@@ -25,6 +25,7 @@ import atexit;
 
 from Test import *
 from Xm import *
+from config import *
 
 class NetworkError(Exception):
     def __init__(self, msg):
@@ -36,6 +37,9 @@ class NetworkError(Exception):
 def undo_dom0_alias(eth, ip):
     traceCommand("ip addr del " + ip + " dev " + eth)
 
+def net_from_ip(ip):
+    return ip[:ip.rfind(".")] + ".0/24"
+    
 class XmNetwork:
 
     def __init__(self):
@@ -56,14 +60,21 @@ class XmNetwork:
         domnum = int(dom[len("dom"):])
         return "169.254."+ str(ethnum+153) + "." + str(domnum+10)
 
-    def ip(self, dom, interface, todomname=None, toeth=None):
+    def ip(self, dom, interface, todomname=None, toeth=None, bridge=None):
         newip = self.calc_ip_address(dom, interface)
 
         # If the testcase is going to talk to dom0, we need to add an 
         # IP address in the proper subnet
         if dom == "dom0":
-            # The domain's vif is a convenient place to add to
-            vifname = "vif" + str(domid(todomname)) + "." + toeth[3:]
+           if ENABLE_HVM_SUPPORT:
+               # HVM uses ioemu which uses a bridge
+               if not bridge:
+                   SKIP("no bridge supplied")
+               else:
+                   vifname = bridge
+           else:
+                # The domain's vif is a convenient place to add to
+                vifname = "vif" + str(domid(todomname)) + "." + toeth[3:]
 
             # register the exit handler FIRST, just in case
             atexit.register(undo_dom0_alias, vifname, newip)
@@ -73,6 +84,15 @@ class XmNetwork:
                                               " dev " + vifname)
             if status:
                 SKIP("\"ip addr add\" failed")
+
+           if ENABLE_HVM_SUPPORT:
+               # We need to add a route to the bridge device
+               network = net_from_ip(newip)
+               status, output = traceCommand("ip route add " + network + " dev " + vifname + " scope link")
+
+                if status:
+                   SKIP("\"ip route add\" failed")
+
         return newip
 
     def mask(self, dom, interface):
index b1952cf0f5155b965444fbb54f1491540cdda25c..3a673cf8cbdf57603a45ab8d9ebc1316246ff226 100644 (file)
@@ -28,7 +28,11 @@ ip   = Net.ip("dom1", "eth0")
 mask = Net.mask("dom1", "eth0")
 
 # Fire up a guest domain w/1 nic
-config = {"vif" : ['ip=%s' % ip]}
+if ENABLE_HVM_SUPPORT:
+    config = {"vif" : ['type=ioemu']}
+else:
+    config = {"vif" : ['ip=%s' % ip ]}
+
 domain = XmTestDomain(extraConfig=config)
 try:
     domain.start()
index 0d218ca0bc701c3934fc99d581ed0cebffb88b33..7e87c43959cb83d3e2dbc15c0df0227af4b2ad58 100644 (file)
@@ -31,7 +31,13 @@ except NetworkError, e:
         FAIL(str(e))
 
 # Fire up a guest domain w/1 nic
-config = {"vif"  : ["ip=%s" % ip]}
+if ENABLE_HVM_SUPPORT:
+    brg = "xenbr0"
+    config = {"vif" : ['type=ioemu, bridge=%s' % brg]}
+else:
+    config = {"vif" : ['ip=%s' % ip ]}
+    brg = None
+
 domain = XmTestDomain(extraConfig=config)
 try:
     domain.start()
@@ -52,7 +58,7 @@ except ConsoleError, e:
 
 try:
     # Add a suitable dom0 IP address 
-    dom0ip = Net.ip("dom0", "eth0", todomname=domain.getName(), toeth="eth0")
+    dom0ip = Net.ip("dom0", "eth0", todomname=domain.getName(), toeth="eth0", bridge=brg)
 except NetworkError, e:
         FAIL(str(e))
 
index 6b4c2a5e52a38d49def2d892c9d6aae6a1732fe6..b35aea9dae4779adb665821c882fdf863f7da47b 100644 (file)
@@ -18,7 +18,11 @@ pingsizes = [ 1, 48, 64, 512, 1440, 1500, 1505, 4096, 4192,
 from XmTestLib import *
 
 def netDomain(ip):
-    config = {"vif"  : ["ip=%s" % ip]}
+    if ENABLE_HVM_SUPPORT:
+        config = {"vif" : ['type=ioemu']}
+    else:
+        config = {"vif" : ['ip=%s' % ip ]}
+
     dom = XmTestDomain(extraConfig=config)
     try:
         dom.start()